"""
  此文件对过滤数据进行测试（测试s、v、acc）
"""

# !处理路径导入问题（添加绝对路径）！！！
import sys
import os
CODE_INTERNAL_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../')) # 生成Code文件夹内部对应的绝对路径
sys.path.append(CODE_INTERNAL_PATH)

# 导入内部包
from utils.read_data import read_original_data
from utils.draw_data import draw_line_chart

# 文件路径常量
FILE_PATH_I80_1_from = "../../../Data/Ngsim数据集/I80数据集/1. 原始数据/trajectories-0400-0415.txt" # 2052 884 18
FILE_PATH_I80_2_from = "../../../Data/Ngsim数据集/I80数据集/1. 原始数据/trajectories-0500-0515.txt" # 1836 526 18
FILE_PATH_I80_3_from = "../../../Data/Ngsim数据集/I80数据集/1. 原始数据/trajectories-0515-0530.txt" # 1790 1153 18
FILE_PATH_101_1_from = "../../../Data/Ngsim数据集/101数据集/1. 原始数据/trajectories-0750am-0805am.txt" # 2169 437 18
FILE_PATH_101_2_from = "../../../Data/Ngsim数据集/101数据集/1. 原始数据/trajectories-0805am-0820am.txt" # 2017 569 18
FILE_PATH_101_3_from = "../../../Data/Ngsim数据集/101数据集/1. 原始数据/trajectories-0820am-0835am.txt" # 1915 421 18

FILE_PATH_I80_1_to = "../../../Data/Ngsim数据集/I80数据集/2. 过滤数据/trajectories-0400-0415_filter.txt" # 2052 884 18
FILE_PATH_I80_2_to = "../../../Data/Ngsim数据集/I80数据集/2. 过滤数据/trajectories-0500-0515_filter.txt" # 1836 526 18
FILE_PATH_I80_3_to = "../../../Data/Ngsim数据集/I80数据集/2. 过滤数据/trajectories-0515-0530_filter.txt" # 1790 1153 18
FILE_PATH_101_1_to = "../../../Data/Ngsim数据集/101数据集/2. 过滤数据/trajectories-0750am-0805am_filter.txt" # 2169 437 18
FILE_PATH_101_2_to = "../../../Data/Ngsim数据集/101数据集/2. 过滤数据/trajectories-0805am-0820am_filter.txt" # 2017 569 18
FILE_PATH_101_3_to = "../../../Data/Ngsim数据集/101数据集/2. 过滤数据/trajectories-0820am-0835am_filter.txt" # 1915 421 18

absolute_path = os.path.abspath(FILE_PATH_I80_1_from)
print("绝对路径", absolute_path)

def extract_test_data(test_data_origin, test_data_filter,  s_idx=5, v_idx=11, acc_idx=12):
  # 提取所有s值
  origin_s = [row[s_idx] * 0.3048 for row in test_data_origin]
  filter_s = [row[s_idx] for row in test_data_filter]
  # 提取所有v值
  origin_v = [row[v_idx] * 0.3048 for row in test_data_origin]
  filter_v = [row[v_idx] for row in test_data_filter]
  # 提取所有acc值
  origin_acc = [row[acc_idx] * 0.3048 for row in test_data_origin]
  filter_acc = [row[acc_idx] for row in test_data_filter]

  return origin_s, filter_s, origin_v, filter_v, origin_acc, filter_acc

def draw_chart(origin_s, filter_s, origin_v, filter_v, origin_acc, filter_acc):
  data_x = [i for i in range(len(origin_s))]

  # 绘制s
  datas_y = [{"data":origin_s, "des":"原始车辆位置"}, {"data":filter_s, "des":"过滤后车辆位置"}]
  labels = {"x":"时间（单位:0.1s）", "y":"位置（单位：m）"}
  draw_line_chart(data_x, datas_y, labels, "车辆纵向坐标")

  # 绘制v
  datas_y = [{"data":origin_v, "des":"原始车辆速度"}, {"data":filter_v, "des":"过滤后车辆速度"}]
  labels = {"x":"时间（单位:0.1s）", "y":"速度（单位：m/s）"}
  draw_line_chart(data_x, datas_y, labels, "车辆速度")

  # 绘制acc
  datas_y = [{"data":origin_acc, "des":"原始车辆加速度"}, {"data":filter_acc, "des":"过滤后车辆加速度"}]
  labels = {"x":"时间（单位:0.1s）", "y":"加速度（单位：m/s^2）"}
  draw_line_chart(data_x, datas_y, labels, "车辆加速度")

if __name__ == '__main__':
  # 读取数据
  origin_data = read_original_data(FILE_PATH_I80_1_from)
  filter_data = read_original_data(FILE_PATH_I80_1_to)

  # 取一组测试数据（一辆车）
  test_data_origin = origin_data[10]
  test_data_filter = filter_data[10]

  # 提取测试数据
  origin_s, filter_s, origin_v, filter_v, origin_acc, filter_acc = extract_test_data(test_data_origin, test_data_filter)

  # 绘图
  draw_chart(origin_s, filter_s, origin_v, filter_v, origin_acc, filter_acc)